/**
 * Skype Vista Gadget
 * 
 * @author kexi
 */

/**
 * Util Class                                 
 */
(function () {
    var Util = window.Util = function () {
        return new Util.fn.init();
    };
    Util.fn = {
        init : function () {
        },
		htmlSpecialChars: ['<', '>', '&', '"', '\''],
		htmlSpecialCharsEscapeTable: {
			'<': '&lt;',
			'>': '&gt;',
			'&': '&amp;',
			'"': '&quot;',
			'\'': '&#039;'
		},
        htmlEncode : function(str) {
            str = str.replace(/&/g,"&amp;") ;
            str = str.replace(/"/g,"&quot;") ;
            str = str.replace(/'/g,"&#039;") ;
            str = str.replace(/</g,"&lt;") ;
            str = str.replace(/>/g,"&gt;") ;
            return str ;
                
        },
		escapeRegExpMetas: function(str){
            return str.replace(/(\W)/g, function(all, $1){
                return '\\' + $1;
            });
        },
        jquerySelectorEscape : function(str) {
            
            //Note: if you wish to use any of the meta-characters described above as a literal part of a name, you must escape the character with two backslashes (\). For example:
            //#foo\\:bar
            //#foo\\[bar\\]
            //#foo\\.bar
            str = str.replace(".", "\\.");
            str = str.replace("[", "\\[");
            str = str.replace(":", "\\:");
            return str;
        }
    }
    Util.fn.init.prototype = Util.fn;
}
)();
var Util = new Util();


/**
 * Emoticon Class
 */
(function(){
    var Emoticon = window.Emoticon = function(name, image, texts){
        return new Emoticon.fn.init(name, image, texts);
    };
    
    Emoticon.fn = {
        init: function(name, image, texts){
            this.name = name;
            this.image = image;
            this.texts = texts;
        },
        getHtml: function(){
            return '<img class="emoticon" src="images/emoticons/' + this.image + '" alt="' + this.name + '"/>';
        },
		toString: function() {
			return this.getHtml();
		}
    };
	Emoticon.fn.init.prototype = Emoticon.fn;
    
    var EmotionUtil = window.EmoticonUtil = {
        emoticons: {
            'Smile': new Emoticon('Smile', 'smile.png', [':)', ':=)', ':-)']),
            'Sad Smile': new Emoticon('Sad Smile', 'sadsmile.png', [':(', ':=(', ':-(']),
            'Big Smile': new Emoticon('Big Smile', 'bigsmile.png', [':D', ':=D', ':-D', ':d', ':=d', ':-d']),
            'Cool': new Emoticon('Cool', 'cool.png', ['8)', '8=)', '8-)', 'B)', 'B=)', 'B-)', '(cool)']),
            'Wink': new Emoticon('Wink', 'wink.png', [':o', ':=o', ':-o', ':O', ':=O', ':-O', ';)']),
            'Crying': new Emoticon('Crying', 'crying.png', [';(', ';-(', ';=(']),
            'Sweating': new Emoticon('Sweating', 'sweating.png', ['(sweat)', '(:|']),
            'Speechless': new Emoticon('Speechless', 'speechless.png', [':|', ':=|', ':-|']),
            'Kiss': new Emoticon('Kiss', 'kiss.png', [':*', ':=*', ':-*']),
            'Tongue Out': new Emoticon('Tongue Out', 'tongueout.png', [':P', ':=P', ':-P', ':p', ':=p', ':-p']),
            'Blush': new Emoticon('Blush', 'blush.png', ['(blush)', ':$', ':-$', ':=$', '":"">"']),
            'Wondering': new Emoticon('Wondering', 'wondering.png', [':^)']),
            'Sleepy': new Emoticon('Sleepy', 'sleepy.png', ['|-)', 'I-)', 'I=)', '(snooze)']),
            'Dull': new Emoticon('Dull', 'dull.png', ['|(', '|-(', '|=(']),
            'In love': new Emoticon('In love', 'inlove.png', ['(inlove)']),
            'Evil grin': new Emoticon('Evil grin', 'evilgrin.png', [']:)', '>:)', '(grin)']),
            'Talking': new Emoticon('Talking', 'talking.png', ['(talk)']),
            'Yawn': new Emoticon('Yawn', 'yawn.png', ['(yawn)', '|-()']),
            'Puke': new Emoticon('Puke', 'puke.png', ['(puke)', ':&', ':-&', ':=&']),
            'Doh!': new Emoticon('Doh!', 'doh.png', ['(doh)']),
            'Angry': new Emoticon('Angry', 'angry.png', [':@', ':-@', ':=@', 'x(', 'x-(', 'x=(', 'X(', 'X-(', 'X=(']),
            'It wasn\'t me': new Emoticon('It wasn\'t me', 'itwasntme.png', ['(wasntme)']),
            'Party!!!': new Emoticon('Party!!!', 'party.png', ['(party)']),
            'Worried': new Emoticon('Worried', 'worried.png', [':S', ':-S', ':=S', ':s', ':-s', ':=s']),
            'Mmm...': new Emoticon('Mmm...', 'mmm.png', ['(mm)']),
            'Nerd': new Emoticon('Nerd', 'nerd.png', ['8-|', 'B-|', '8|', 'B|', '8=|', 'B=|', '(nerd)']),
            'Lips Sealed': new Emoticon('Lips Sealed', 'lipssealed.png', [':x', ':-x', ':X', ':-X', ':#', ':-#', ':=x', ':=X', ':=#']),
            'Hi': new Emoticon('Hi', 'hi.png', ['(hi)', '(wave)','(bye)']),
            'Call': new Emoticon('Call', 'call.png', ['(call)']),
            'Devil': new Emoticon('Devil', 'devil.png', ['(devil)']),
            'Angel': new Emoticon('Angel', 'angel.png', ['(angel)']),
            'Envy': new Emoticon('Envy', 'envy.png', ['(envy)']),
            'Wait': new Emoticon('Wait', 'wait.png', ['(wait)']),
            'Bear': new Emoticon('Bear', 'bear.png', ['(bear)', '(hug)']),
            'Make-up': new Emoticon('Make-up', 'makeup.png', ['(makeup)', '(kate)']),
            'Covered Laugh': new Emoticon('Covered Laugh', 'giggle.png', ['(giggle)', '(chuckle)']),
            'Clapping Hands': new Emoticon('Clapping Hands', 'clapping.png', ['(clap)']),
            'Thinking': new Emoticon('Thinking', 'thinking.png', ['(think)', ':?', ':-?', ':=?']),
            'Bow': new Emoticon('Bow', 'bow.png', ['(bow)']),
            'Rolling on the floor laughing': new Emoticon('Rolling on the floor laughing', 'rofl.png', ['(rofl)']),
            'Whew': new Emoticon('Whew', 'whew.png', ['(whew)']),
            'Happy': new Emoticon('Happy', 'happy.png', ['(happy)']),
            'Smirking': new Emoticon('Smirking', 'smirk.png', ['(smirk)']),
            'Nodding': new Emoticon('Nodding', 'nod.png', ['(nod)']),
            'Shaking': new Emoticon('Shaking', 'shake.png', ['(shake)']),
            'Punch': new Emoticon('Punch', 'punch.png', ['(punch)']),
            'Emo': new Emoticon('Emo', 'emo.png', ['(emo)']),
            'Yes': new Emoticon('Yes', 'yes.png', ['(y)', '(Y)', '(ok)']),
            'No': new Emoticon('No', 'no.png', ['(n)', '(N)']),
            'Shaking Hands': new Emoticon('Shaking Hands', 'handshake.png', ['(handshake)']),
            'Skype': new Emoticon('Skype', 'skype.png', ['(skype)', '(ss)']),
            'Heart': new Emoticon('Heart', 'heart.png', ['(h)', '(H)', '(l)', '(L)']),
            'Broken heart': new Emoticon('Broken heart', 'brokenheart.png', ['(u)', '(U)']),
            'Mail': new Emoticon('Mail', 'mail.png', ['(e)', '(m)']),
            'Flower': new Emoticon('Flower', 'flower.png', ['(f)', '(F)']),
            'Rain': new Emoticon('Rain', 'rain.png', ['(rain)', '(london)', '(st)']),
            'Sun': new Emoticon('Sun', 'sun.png', ['(sun)']),
            'Time': new Emoticon('Time', 'time.png', ['(o)', '(O)', '(time)']),
            'Music': new Emoticon('Music', 'music.png', ['(music)']),
            'Movie': new Emoticon('Movie', 'movie.png', ['(~)', '(film)', '(movie)']),
            'Phone': new Emoticon('Phone', 'phone.png', ['(mp)', '(ph)']),
            'Coffee': new Emoticon('Coffee', 'coffee.png', ['(coffee)']),
            'Pizza': new Emoticon('Pizza', 'pizza.png', ['(pizza)', '(pi)']),
            'Cash': new Emoticon('Cash', 'cash.png', ['(cash)', '(mo)', '($)']),
            'Muscle': new Emoticon('Muscle', 'muscle.png', ['(muscle)', '(flex)']),
            'Cake': new Emoticon('Cake', 'cake.png', ['(^)', '(cake)']),
            'Beer': new Emoticon('Beer', 'beer.png', ['(beer)']),
            'Drink': new Emoticon('Drink', 'drink.png', ['(d)', '(D)']),
            'Dance': new Emoticon('Dance', 'dance.png', ['(dance)', '\\o/', '\\:D/', '\\:d/']),
            'Ninja': new Emoticon('Ninja', 'ninja.png', ['(ninja)']),
            'Star': new Emoticon('Star', 'star.png', ['(*)']),
            'Mooning': new Emoticon('Mooning', 'mooning.png', ['(mooning)']),
            'Finger': new Emoticon('Finger', 'middlefinger.png', ['(finger)']),
            'Bandit': new Emoticon('Bandit', 'bandit.png', ['(bandit)']),
            'Drunk': new Emoticon('Drunk', 'drunk.png', ['(drunk)']),
            'Smoking': new Emoticon('Smoking', 'smoke.png', ['(smoking)', '(smoke)', '(ci)']),
            'Toivo': new Emoticon('Toivo', 'toivo.png', ['(toivo)']),
            'Rock': new Emoticon('Rock', 'rock.png', ['(rock)']),
            'Headbang': new Emoticon('Headbang', 'headbang.png', ['(headbang)', '(banghead)']),
            'Bug': new Emoticon('Bug', 'bug.png', ['(bug)']),
            'Fubar': new Emoticon('Fubar', 'fubar.png', ['(fubar)']),
            'Poolparty': new Emoticon('Poolparty', 'poolparty.png', ['(poolparty)']),
            'Swearing': new Emoticon('Swearing', 'swear.png', ['(swear)']),
            'TMI': new Emoticon('TMI', 'tmi.png', ['(tmi)']),
            'Heidy': new Emoticon('Heidy', 'heidy.png', ['(heidy)'])
        },
        init: function(){
            // Create RegExp Object & Search Array
			this.texts = {};
            for (var i in this.emoticons) {
                var textsLength = this.emoticons[i].texts.length;
                for (var j = 0; j < textsLength; j++) {
					this.texts[this.emoticons[i].texts[j]] = this.emoticons[i];
                }
			}
        }
    }
	EmoticonUtil.init();
})();


